package ms.maplestory.boot.bootstrap;

import ms.maplestory.boot.Server;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

import java.util.Arrays;

@Configuration
@RequiredArgsConstructor
public class ServerBootstrap {

    private final Server server;

    @EventListener
    public void createServerHandler(ApplicationReadyEvent event) {
        ConfigurableApplicationContext applicationContext = event.getApplicationContext();
        String[] activeProfiles = applicationContext.getEnvironment().getActiveProfiles();
        if (Arrays.asList(activeProfiles).contains("junit")) {
            return;
        }
        server.init(null);
    }
}
